<?php
if(php_sapi_name()==="cli"){
    date_default_timezone_set("PRC");
    while(true){
        printf("\033c");
        printf("[\033[32mTray\033[0m] Running\n");
        printf("[\033[32mTray\033[0m] Time is \033[4m%s\033[0m\n",date("H:i:s"));
        @touch("mission");
        $a=@file_get_contents("mission");
        if (empty($a)){
            $a=json_encode([]);
            @file_put_contents("mission",$a);
        }
        $a=json_decode($a,true);
        if (isset($a["missions"])){
            $c = count($a["missions"]);
            if ($c>0){
                printf("[\033[32mTray\033[0m] $c missions\n\n");
                foreach ($a["missions"] as $k=>$v) {
                    @printf("[\033[32mTray\033[0m] %s control=%s id=%s data=%s\n",((int)$k)+1,$v["control"],$v["id"],$v["data"]);
                }
            }else{
                printf("[\033[32mTray\033[0m] Empty missions");
            }
        }else{
            printf("[\033[32mTray\033[0m] No missions");
        }
        printf("\033[?25l");
        usleep(999999);
    }
}else{
    echo "You can only run it in cmd";
}